/**
 * 替换null
 */
function replaceNull(string, replaceString) {
    if (string == null || string == 'undefinde' || string == 'null') {
        return replaceString;
    } else {
        return string;
    }
}

// 字典数据
var dictList = null;

function getDictList() {
    if (dictList == null) {
        loadGetServer("/manager/system/getAllDictMap", {}, function (data) {
            dictList = data.dictMap;
        })
    }
    return dictList;
}

/**
 * 根据dictType获取字典数据
 */
function getDictByType(dictType) {
    if (dictList == null) {
        getDictList();
    }
    for (var i = 0; i < dictList.length; i++) {
        var dictListElement = dictList[i];
        if (dictListElement.name == dictType) {
            return dictListElement.value;
        }
    }
}

/**
 * 根据dictType和dictValue获取字典标签
 */
function getHtmlDictTd(dictType, dictValue) {
    var dicts = getDictByType(dictType)
    var html = "<td></td>";
    for (var i = 0; i < dicts.length; i++) {
        var dict = dicts[i];
        if (dict.dict_value == dictValue) {
            html = "<td><span class='label label-sm " + dict.css_class + "'>" + dict.dict_label + "</span></td>"
        }
    }
    return html;
}

/**
 * 根据dictType拼接option
 */
function getHtmlDictOption(dictType) {
    var dicts = getDictByType(dictType)
    var html = "";
    html += "<option value=''>请选择</option>";
    for (var i = 0; i < dicts.length; i++) {
        var dict = dicts[i];
        html += "<option value='" + dict.dict_value + "'>" + dict.dict_label + "</option>";
    }
    return html;
}

/**
 * 时间按钮
*/
function initDate(){
    var dateRange1 = new pickerDateRange('date1', {
        isTodayValid: true,
        needCompare: false,
        defaultText: ' 至 ',
        autoSubmit: true,
        theme: 'ta',
        success: function (obj) {
            $("#startTime").val(obj.startDate);
            $("#endTime").val(obj.endDate);
        }
    });
}

/**
 * 文本框为空时为时间值赋空值
 */
function onb() {
    var dateTime = $("#date1").val();
    if (dateTime == null || dateTime == "") {
        $("#startTime").val("");
        $("#endTime").val("");
    }
}

